package br.com.Orange.view.form.cliente;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import br.com.Orange.negocio.cliente.model.Cliente;

public class AtualizarClienteForm extends ActionForm{

	private static final long serialVersionUID = 3501684423099993017L;
	
	private Cliente cliente = new Cliente();
	
	public Cliente getCliente(){
		return this.cliente;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors erros = new ActionErrors();
		if (cliente.getCPF() == null ||
				cliente.getCPF().trim().equalsIgnoreCase("")){
			erros.add(("CPF"), new ActionMessage("erro.cliente.campoCPF"));
		
		}else if (cliente.getNome() == null ||
				cliente.getNome().trim().equalsIgnoreCase("")){
			erros.add(("nome"), new ActionMessage("erro.cliente.campoNome"));

		}
		
		
		return erros;
	}


	/* (non-Javadoc)
	 * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.cliente = new Cliente();
		
	}
	
}
